﻿using Furion.DependencyInjection;
using Furion.EventBus;

namespace WebApplication1.Events
{
    public class OrderEvent: IEventSubscriber, ISingleton
    {
        private readonly ILogger<OrderEvent> logger;

        public OrderEvent(ILogger<OrderEvent> logger)
        {
            this.logger = logger;
        }

        /// <summary>
        /// 当订单创建成功时，发送订单创建成功通知
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        [EventSubscribe("Order:Create")]
        public async Task SendCreateOrderNotify(EventHandlerExecutingContext context)
        {
            logger.LogInformation(context.HandlerMethod.Name + ": 订单创建通知已发送");
            await Task.CompletedTask;
        }

        /// <summary>
        /// 当订单创建成功时，扣减商品库存
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        [EventSubscribe("Order:Create")]
        public async Task ReduceProductCount(EventHandlerExecutingContext context)
        {
            logger.LogInformation(context.HandlerMethod.Name + ": 商品库存扣减成功");
            await Task.CompletedTask;
        }

    }
}
